package com.hotel.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.mapper.InventoryMapper;
import com.hotel.pojo.WorkerSalaries;
import com.hotel.service.InventoryService;
import com.hotel.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author by LuJinRong
 * @date 2021/8/3。
 * @time 17:18。
 */
@Service
public class InventoryServiceImpl implements InventoryService {

    @Autowired
    private InventoryMapper inventoryMapper;
    @Override
    public PageResult findAll(PageResult pageResult) {
        IPage iPage = new Page(pageResult.getPageNum(), pageResult.getPageSize());
        //2.构建查询条件构造器
//        QueryWrapper queryWrapper = new QueryWrapper();
        // List<WorkerSalaries> list = workerSalariesMapper.selectList(null);
        //判断用户数据是否有效  有效 true   无效 false
//        boolean flag = StringUtils.hasLength(pageResult.getQuery());
//        queryWrapper.like(flag, "workerName", pageResult.getQuery());
        //经过MP分页查询将所有的分页(total/结果/页面/条数/xxx)数据封装到iPage对象
        iPage = inventoryMapper.selectPage(iPage,null);
        //从分页对象中获取总记录数
        long total = iPage.getTotal();
        System.out.println(total);
        //从分页对象中获取分页后的结果
        List<WorkerSalaries> rows = iPage.getRecords();
        return pageResult.setTotal(total).setRows(rows);
        //需要返回的是5个参数
    }
}
